package com.appliance.chamliga.touchimage;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;

import com.appliance.chamliga.RootActivity;

public class ImageActivity extends RootActivity {
	private static Bitmap bmLargeImage; // bitmap large enough to be scrolled

	@Override
	protected void onDestroy() {
		try {
			bmLargeImage.recycle();
			bmLargeImage = null;
			System.gc();
		} catch (Exception e) {
			// TODO: handle exception
		}
		// Log.i("## ImageDestroy", "bitmap is recycled");
		super.onDestroy();
	}

	// Physical display width and height.
	private static int displayWidth = 0;
	private static int displayHeight = 0;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setup();
		Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		displayWidth = display.getWidth();
		displayHeight = display.getHeight();

		final TouchImageView tiv = new TouchImageView(this);

		try {
			bmLargeImage = getImage();

			tiv.setImage(bmLargeImage, displayWidth, displayHeight);

			setContentView(tiv);
			Toast.makeText(getApplicationContext(), "Use multitouch to zoom", Toast.LENGTH_SHORT);
		} catch (Exception e) {
			this.finish();
		} catch (OutOfMemoryError e) {
			this.finish();
		}
	}

	public void setup() {
	}
}
